package collection;

import java.util.HashMap;
import java.util.Map;

public class HashMapDemo {
    public static void main(String[] args) {
        // build
        Map<String, Object> map = new HashMap<String, Object>();
        System.out.println(map.isEmpty());
        map.put("a", 1);
        map.putAll(new HashMap<String, Object>() {
            {
                put("b", 2);
                put("c", 3);
            }
        });
        System.out.println(map.isEmpty());
        System.out.println(map.size());
        // browse
        System.out.println(map);
        System.out.println(map.entrySet());
        System.out.println(map.keySet());
        System.out.println(map.values());
        // search
        String key = "a";
        if (map.containsKey(key)) {
            System.out.println(map.get(key));
            Object value = map.remove(key);
            System.out.println(value);
            System.out.println(map.containsValue(value));
            System.out.println(map.size());
        }
        // compare
        Map<String, Object> map2 = new HashMap<String, Object>();
        map2.putAll(map);
        System.out.println(map.equals(map2));
        map.clear();
        System.out.println(map.isEmpty());
        System.out.println(map.equals(map2));
    }
}
